<template>
  <div>
    <p>前端版本: {{ frontendVersion }}</p>
    <el-card title="后端版本信息">
      <el-table :data="backendVersion" stripe>
        <el-table-column prop="name" label="模块名称"></el-table-column>
        <el-table-column prop="vision" label="版本号"></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import axios from 'axios';
import {reqGetArticleVision, reqGetFileleVision, reqGetMapVision, reqGetUserVision} from "@/api/info";
import {requestGetData, requestIsSuccess} from "@/api/request";
import {warningMessage} from "@/utils/message";

export default {
  data() {
    return {
      frontendVersion: process.env.VUE_APP_VERSION,
      backendVersion: []
    };
  },
  async created() {
    try {
      let result = await reqGetUserVision()
      if(requestIsSuccess(result))
      {
        this.backendVersion.push({
              name:"user",
              vision:requestGetData(result).userServiceVision
            });
      }
      result = await reqGetArticleVision()
      if(requestIsSuccess(result))
      {
        this.backendVersion.push({
              name:"article",
              vision:requestGetData(result).articleServiceVision
        });
      }
      result = await reqGetFileleVision()
      if(requestIsSuccess(result))
      {
        this.backendVersion.push({
              name:"file",
              vision:requestGetData(result).fileServiceVision
        });
      }
      result = await reqGetMapVision()
      if(requestIsSuccess(result))
      {
        this.backendVersion.push({
              name:"map",
              vision:requestGetData(result).mapServiceVision
        });
      }
    } catch (error) {
      warningMessage('获取后端版本信息失败:', error);
    }
  }
};
</script>